<template>
  <div class="todo-footer" v-show="total">
    <label>
      <!-- <input type="checkbox" :checked="isAll" @change="TotalChecked" /> -->
      <input type="checkbox" v-model="isAll" />
    </label>
    <span>
      <span>已完成{{ FinishedTatol }}</span> / 全部{{ total }}
    </span>
    <button @click="ClearTodos" class="btn btn-danger">清除已完成任务</button>
  </div>
</template>

<script>
export default {
  ///ooo父亲的方法也可以作为Props传
  props: ["TodoList", "ClearTodos"],
  computed: {
    total() {
      return this.TodoList.length;
    },
    //ooo
    FinishedTatol() {
      // return this.TodoList.reduce((pre,element)=>pre + (element.done?1:0))
      return this.TodoList.reduce((pre, todo) => pre + (todo.done ? 1 : 0), 0);
    },

    // isAll() {
    //   return this.total === this.FinishedTatol;
    // },
    //ooo优化
    isAll: {
      get() {
        return this.total === this.FinishedTatol;
      },
      set(newvalue) {
        console.log(newvalue);
        this.$emit("TotalChecked", newvalue);
      },
    },
  },
  methods: {
    // 组件自定义，子传父
    /* TotalChecked() {
      this.$emit("TotalChecked", this.isAll);
    }, */
  },
};
</script>

<style>
/*footer*/
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>